# Contributor: Henrik Riomar <henrik.riomar@gmail.com>
# Maintainer: Drew DeVault <sir@cmpwn.com>
pkgname=swaylock
pkgver=1.5
pkgrel=3
pkgdesc="Screen locker for Wayland"
url="https://swaywm.org"
arch="all"
license="MIT"
options="!check" # no test suite
makedepends="cairo-dev
	gdk-pixbuf-dev
	libxkbcommon-dev
	linux-pam-dev
	meson
	ninja
	scdoc
	wayland-dev
	wayland-protocols
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion:bashcomp:noarch
	$pkgname-fish-completion:fishcomp:noarch
	$pkgname-zsh-completion:zshcomp:noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/swaywm/swaylock/archive/$pkgver.tar.gz"

prepare() {
	default_prepare
	sed -i 's/login/base-auth/g' \
		pam/swaylock

	cat <<-__EOF__ >> pam/swaylock

	# Unlock GNOME Keyring if available
	-auth       optional     pam_gnome_keyring.so
	-session    optional     pam_gnome_keyring.so auto_start

	# Unlock KWallet if available
	-auth    optional        pam_kwallet.so
	-auth    optional        pam_kwallet5.so
	-session optional        pam_kwallet.so auto_start
	-session optional        pam_kwallet5.so auto_start
	__EOF__

}

build() {
	meson \
		--prefix=/usr \
		--buildtype=plain \
		build
	ninja -C build
}

package() {
	DESTDIR="$pkgdir" ninja -C build install
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share/
	mv "$pkgdir"/usr/share/bash-completion "$subpkgdir"/usr/share/
}

fishcomp() {
	depends=""
	pkgdesc="Fish completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel fish"

	mkdir -p "$subpkgdir"/usr/share/fish
	mv "$pkgdir"/usr/share/fish/vendor_completions.d "$subpkgdir"/usr/share/fish/completions
}

zshcomp() {
	depends=""
	pkgdesc="Zsh completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	mkdir -p "$subpkgdir"/usr/share/zsh
	mv "$pkgdir"/usr/share/zsh/site-functions "$subpkgdir"/usr/share/zsh
}
sha512sums="16dd9b912ca702849290cf18d91ffbd64a70118cc284982a84b567c4974fd4590b12707c0aae1fcda7ccd1caa7880f342c633b9345bd795c36702916696d1f67  swaylock-1.5.tar.gz"
